package com.example.ordersystem.controller;

import com.example.ordersystem.common.Result;
import com.example.ordersystem.entity.Admin;
import com.example.ordersystem.service.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin")
@CrossOrigin
public class AdminController {

    @Resource
    private AdminService adminService;

    @PostMapping("/login")
    public Result<Admin> login(@RequestParam String username, @RequestParam String password) {
        Admin admin = adminService.login(username, password);
        if (admin != null) {
            return Result.success(admin);
        }
        return Result.error("用户名或密码错误");
    }
}